﻿// JScript 文件

var GJSB_COLOR_RED = "#ff0000";
var GJSB_COLOR_LIGHTRED = "#ffdcdc";
var GJSB_COLOR_LIGHTBLUE = "#bed2ff";
var GJSB_COLOR_ORANGE ="#ff8040";
var GJSB_COLOR_PURPLE = "#8000ff";
var GJSB_COLOR_CATSUP = "#808000";
var GJSB_COLOR_BLUE = "blue";
var GJSB_COLOR_RED = "red";
var GJSB_COLOR_GREEN = "green";
var GJSB_COLOR_GRAY = "gray";
var GJSB_COLOR_YELLOW = "yellow";
var GJSB_COLOR_BLACK = "black";
var GJSB_COLOR_WHITE = "white";

function DrawGjsb()
{
    this.Init = Init;
    this.DrawGjsbMbOdf = DrawGjsbMbOdf;
    this.DrawGjsbMbNotOdf = DrawGjsbMbNotOdf;
    this.DrawDz = DrawDz;
    this.DrawOdm = DrawOdm;
    this.DrawEmptyOdm = DrawEmptyOdm;
    this.DrawBlock = DrawBlock;
    this.DrawEmptyBlock = DrawEmptyBlock;
    this.GetBlockLeftTopPos = GetBlockLeftTopPos;
    this.CalDzCoord = CalDzCoord;
    this.GetBlockWidth = GetBlockWidth;
    this.GetBlockHeight = GetBlockHeight;
    this.m_iRad = 6;
    this.m_iBlockRowDistance = this.m_iRad*4;
    this.m_iBlockLineDistance = this.m_iRad*4;
    this.m_iDzRowDistance = this.m_iRad*3; 
    this.m_iDzLineDistance = this.m_iRad*3; 
    this.m_iBaseX = this.m_iRad*5;
    this.m_iBaseY = this.m_iRad*5;
    this.m_objBaseDrawDz = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:"dzdiv", 
                            stroked:true,
                            strokeweight: "1px", 
                            strokecolor: GJSB_COLOR_BLACK,
                            zIndex:10,
                            OnMouseClick: {fun:setDzAtt}
                            }); //new BaseDraw("dzdiv");
                        
    this.m_objBaseDrawWlgq = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:"wlgqdiv", 
                            strokeweight: "1px", 
                            strokecolor: GJSB_COLOR_WHITE,
                            zIndex:2
                            }); //new BaseDraw("wlgqdiv");
    this.m_objBaseDrawJxgq = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:"jxgqdiv", 
                            strokeweight: "1px", 
                            strokecolor: GJSB_COLOR_WHITE,
                            fill:GJSB_COLOR_LIGHTRED,
                            opacity:0,
                            zIndex:2,
                            bhidden:true
                            });//new BaseDraw("jxgqdiv");
    this.m_objGjsbMbGlInfo = null;
    this.m_objBaseDrawBk = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:"bkgroup", 
                            stroked:true,
                            strokeweight: "1px", 
                            strokecolor: GJSB_COLOR_BLACK,
                            zIndex:1
                            });//new BaseDraw("bkgroup");
}

function Init(GjsbMbGlInfo)
{
    this.m_objGjsbMbGlInfo = GjsbMbGlInfo;
}

function DrawGjsbMbOdf()
{
    var                             i;
    var                             OdmInfo = new ODM_INFO();
    
    for (i = 1; i <= this.m_objGjsbMbGlInfo.OdfDzMbInfo.LMks; i++)
    {
        OdmInfo = this.m_objGjsbMbGlInfo.GetOdmByWlkh(i);
        try
        {
            if (OdmInfo != null)
            {
                this.DrawOdm(OdmInfo);
            }
            else
            {
                this.DrawEmptyOdm();
            }
        }
        catch(e)
        {
        }
    }
    return "";
    //return this.m_objBaseDrawBk.getVmlCode() + this.m_objBaseDrawWlgq.getVmlCode() + this.m_objBaseDrawJxgq.getVmlCode()// + this.m_objBaseDrawDz.getVmlCode();
}

//画ODF面板
function DrawGjsbMbNotOdf()
{
    var                             i, j;
    var                             GjsbdzBlock = new GJSBDZ_BLOCK();
    
    for (i = 1; i <= this.m_objGjsbMbGlInfo.GjsbDzMbInfo.LMks; i++)
    {
        for (j = 1; j <= this.m_objGjsbMbGlInfo.GjsbDzMbInfo.Ls; j++)
        {
            GjsbdzBlock = this.m_objGjsbMbGlInfo.GetBlockByMkHhLh(i, j);
            if (GjsbdzBlock != null)
            {
                this.DrawBlock(GjsbdzBlock);
            }
            else
            {
                this.DrawEmptyBlock(i, j);
            }
        }
    } 
    return "";
    //return this.m_objBaseDrawBk.getVmlCode() + this.m_objBaseDrawWlgq.getVmlCode() + this.m_objBaseDrawJxgq.getVmlCode()// + this.m_objBaseDrawDz.getVmlCode();
}

//画端子


function DrawDz(GjsbDzPos)
{
    var             x, y;
    var             dot;
    var             GjsbDzJmp = null;
    var             DzInfo = null;
    var             GjsbDzCd = null;
    var             CdRectLeft, CdRectTop, CdRectWidth, CdRectHeight;
    var             DzColor;
    var             Tip = "";
    var             DzGr = null;
    
    dot = this.CalDzCoord(GjsbDzPos);
    x = dot[0];
    y = dot[1];         //根据端子物理位置得到端子信息
    DzInfo = this.m_objGjsbMbGlInfo.GetDzInfoByPos(GjsbDzPos);
    if (DzInfo == null)
    {
        return;
    }
    Tip += "第"+DzInfo.Dz.Dzh+"号端子";
    GjsbDzJmp = this.m_objGjsbMbGlInfo.getDzGlTjInfo(DzInfo.Dz.Kh, DzInfo.Dz.Dzh);
    if (GjsbDzJmp != null)
    {
        if (GjsbDzJmp.RdDz.DevBm == null)
        {
            if ((GjsbDzJmp.RdDz.Kh == DzInfo.Dz.Kh) && (GjsbDzJmp.RdDz.Dzh == DzInfo.Dz.Dzh)) 
            {
                Tip += "\n与"+GjsbDzJmp.CdDz.Dzh+"号端子跳接";
            }
            else
            {
                Tip += "\n与"+GjsbDzJmp.RdDz.Dzh+"号端子跳接";
            }
        }
        else
        {
            if ((GjsbDzJmp.RdDz.DevBm == DzInfo.Dz.DevBm) && 
                (GjsbDzJmp.RdDz.Kh == DzInfo.Dz.Kh) &&
                (GjsbDzJmp.RdDz.Dzh == DzInfo.Dz.Dzh)) 
            {
                Tip += "\n与"+GjsbDzJmp.CdDz.Dzh+"号端子跳接";
            }
            else
            {
                Tip += "\n与"+GjsbDzJmp.RdDz.Dzh+"号端子跳接";
            }
        }
    }
    DzGr = this.m_objGjsbMbGlInfo.getDzGlGrInfo(DzInfo.Dz.Kh, DzInfo.Dz.Dzh);
    if (DzGr != null)
    {
        Tip += "\n光路编码:"+DzGr.GrBm;
    }
    switch (DzInfo.State)
    {
        case enumPORT_STATE_IDLE:       //空闲，白色


            DzColor = GJSB_COLOR_WHITE;
            break;
        case enumPORT_STATE_USED:       //占用，绿色


            DzColor = GJSB_COLOR_GREEN;
            break;                  
        case enumPORT_STATE_PREUSE:     //预占，蓝色


            DzColor = GJSB_COLOR_BLUE;
            break;
        case enumPORT_STATE_RESERVE:    //保留，黄色


            DzColor = GJSB_COLOR_YELLOW;
            break;
        case enumPORT_STATE_BAD:        //损坏，黑色


            DzColor = GJSB_COLOR_BLACK;
            break;
        case enumPORT_STATE_OTHER:      //其他，灰色


            DzColor = GJSB_COLOR_GRAY;
            break;
    }                               //根据端子号得到成端信息


　　　　　　　　　　　　　　　　　//画物理光纤

    GjsbDzCd = this.m_objGjsbMbGlInfo.getDzGlCdInfo(DzInfo.Dz.Kh, DzInfo.Dz.Dzh);
    if (GjsbDzCd != null)
    {
		CdRectLeft = x-this.m_iDzLineDistance/2;
		CdRectTop = y-this.m_iDzRowDistance/2;
		CdRectWidth = this.m_iDzLineDistance;
		CdRectHeight = this.m_iDzRowDistance;   //画端子板的矩形框
        //this.m_objBaseDrawWlgq.drawRect(0, CdRectLeft, CdRectTop, CdRectWidth, CdRectHeight, 0, GJSB_COLOR_LIGHTBLUE, GJSB_COLOR_WHITE, false);
       
        this.m_objBaseDrawWlgq.drawRect({id:"0",x:CdRectLeft,y:CdRectTop,w:CdRectWidth,h:CdRectHeight,fill:GJSB_COLOR_LIGHTBLUE});

       
        Tip += "\n与光缆段"+GjsbDzCd[0].CdQx.GldBm+"的"+GjsbDzCd[0].CdQx.Qxh+"号纤芯关联";
    }

　　　　　　　　　　　　　　　　　//画局向光纤

    GjsbDzJxgq = this.m_objGjsbMbGlInfo.getDzGlJxgqInfo(DzInfo.Dz.Kh, DzInfo.Dz.Dzh);
    if (GjsbDzJxgq != null)
    {
		JxgqRectLeft = x-this.m_iDzLineDistance/2;
		JxgqRectTop = y-this.m_iDzRowDistance/2;
		JxgqRectWidth = this.m_iDzLineDistance;
		JxgqRectHeight = this.m_iDzRowDistance;   //画端子板的矩形框
        //this.m_objBaseDrawJxgq.drawRect(0, JxgqRectLeft, JxgqRectTop, JxgqRectWidth, JxgqRectHeight, 0, GJSB_COLOR_LIGHTRED, GJSB_COLOR_WHITE, false);
        
        this.m_objBaseDrawJxgq.drawRect({id:"0",x:JxgqRectLeft,y:JxgqRectTop,w:JxgqRectWidth,h:JxgqRectHeight});
        
        Tip += "\n与局向光纤"+GjsbDzJxgq[0].JxgqBm+"关联";
    }

                                    //画端子    var Dzbm;
    if(DzInfo.Dz.Kh == DEFAULT_KH || DzInfo.Dz.Kh == null)
    {
        Dzbm = "null/" + DzInfo.Dz.Dzh;
    }
    else
    {
        Dzbm = DzInfo.Dz.Kh + "/" + DzInfo.Dz.Dzh;
    }

    //this.m_objBaseDrawDz.drawCircle(Dzbm, x, y, this.m_iRad, Tip, DzColor, GJSB_COLOR_BLACK, true,"setDzAtt");
    this.m_objBaseDrawDz.drawCircle({id:Dzbm,x:x,y:y,r:this.m_iRad,fill:DzColor},
                                    {att:[{name:"dzfill",val:DzColor},{name:"sel",val:"false"},{name:"title",val:Tip},{name:"tip",val:Tip}]});
    if (GjsbDzJmp != null)
    {                               //画跳接

         this.m_objBaseDrawDz.drawCircle({id:Dzbm,x:x,y:y,r:this.m_iRad/2,fill:GJSB_COLOR_WHITE,strokecolor:GJSB_COLOR_WHITE},
                                    {att:[{name:"dzfill",val:DzColor},{name:"sel",val:"false"},{name:"title",val:Tip},{name:"tip",val:Tip}]});
        //this.m_objBaseDrawDz.drawCircle(Dzbm, x, y, this.m_iRad/2, Tip, GJSB_COLOR_WHITE, GJSB_COLOR_WHITE, true,"setDzAtt");
    }    
}

function DrawOdm(OdmInfo)
{
    var         Temp;
    var         iOdmDzhs = 1;
    var         iOdmDzls = 1;
	var         iMdyhs = 1;
	var         iMdyls = 1;
	var         iMbhs = 1;
	var         iMbls = 1;
	var         BlockLeft, BlockTop, BlockWidth, BlockHeight;
	var         BlockLeftTopPos;
	var         str;
	var         GjsbDzPos = new GJSB_DZ_POS();
	
	Temp = this.m_objGjsbMbGlInfo.GetOdmHls(OdmInfo);
	iOdmDzhs = Temp[0];
	iOdmDzls = Temp[1];
	BlockLeftTopPos = this.GetBlockLeftTopPos(OdmInfo.WlKh, 1);
    BlockLeft = BlockLeftTopPos[0];
    BlockTop = BlockLeftTopPos[1];
    BlockWidth = this.GetBlockWidth(iOdmDzls);
    BlockHeight = this.GetBlockHeight(iOdmDzhs);
    
	if (OdmInfo.strKh != "")
	{
	    str = "第"+OdmInfo.Kh+"框";
	    if (OdmInfo.Bz != "")
	    {
	        str += "("+OdmInfo.Bz+")";
	    }
        //this.m_objBaseDrawBk.drawText(0, BlockLeft, BlockTop-this.m_iRad*3, str);
        
        this.m_objBaseDrawBk.drawText({id:0,x:BlockLeft,y:BlockTop-this.m_iRad*3,text:str,bsvg:true});
        
	}
	if (this.m_objGjsbMbGlInfo.OdfDzMbInfo.KPlfs == enumPORT_LAY_UPTODOWN)
	{
	    str = ""+OdmInfo.WlKh;
	}
	else
	{
		str = (this.m_objGjsbMbGlInfo.OdfDzMbInfo.LMks-OdmInfo.WlKh+1) + "";
	}
    //this.m_objBaseDrawBk.drawText(0, BlockLeft-this.m_iRad*3, BlockTop, str);
    //this.m_objBaseDrawBk.drawRect(0, BlockLeft, BlockTop, BlockWidth, BlockHeight, 0, GJSB_COLOR_WHITE);
    
    this.m_objBaseDrawBk.drawText({id:0,x:BlockLeft-this.m_iRad*3,y:BlockTop,text:str,bsvg:true});
    this.m_objBaseDrawBk.drawRect({id:0,x:BlockLeft,y:BlockTop,w:BlockWidth,h:BlockHeight,fill:GJSB_COLOR_WHITE});
    

    GjsbDzPos.MkHh = OdmInfo.WlKh;
    GjsbDzPos.MkLh = 1;
	for (i = 1; i <= iOdmDzhs; i++)
	{
		for (j = 1; j <= iOdmDzls; j++)
		{
			GjsbDzPos.Row = i;
			GjsbDzPos.Line = j;
			this.DrawDz(GjsbDzPos);
		}
	}
/*
	if (pOdmInfo->iDys > 1)
	{
		CPoint			TempPoint1;
		CPoint			TempPoint2;

		if ((pOdmInfo->Dyplfs == enumPORT_LAY_UPTODOWN) || (pOdmInfo->Dyplfs == enumPORT_LAY_DOWNTOUP))
		{
			double				dDyGd;	//µ¥Ôª¸ß¶È

			dDyGd = 1.0*(OdmRect.bottom-OdmRect.top-2*m_iRad)/pOdmInfo->iDys;
			for (i = 1; i < pOdmInfo->iDys; i++)
			{
				TempPoint1.x = OdmRect.left;
				TempPoint1.y = OdmRect.top+m_iRad+int(i*dDyGd)-i+2;
				TempPoint2.x = OdmRect.right;
				TempPoint2.y = TempPoint1.y;
				m_pDC->MoveTo(TempPoint1);
				m_pDC->LineTo(TempPoint2);
			}
		}
		else
		{
			double				dDyKd;	//µ¥Ôª¿í¶È

			dDyKd = 1.0*(OdmRect.right-OdmRect.left-2*m_iRad)/pOdmInfo->iDys;
			for (i = 1; i < pOdmInfo->iDys; i++)
			{
				TempPoint1.x = OdmRect.left+m_iRad+int(i*dDyKd)-i+2;
				TempPoint1.y = OdmRect.top;
				TempPoint2.x = TempPoint1.x;
				TempPoint2.y = OdmRect.bottom;
				m_pDC->MoveTo(TempPoint1);
				m_pDC->LineTo(TempPoint2);
			}
		}
	}
	*/
}

function DrawEmptyOdm(WlKh)
{
	var						OdmInfo = new ODM_INFO();

	OdmInfo.WlKh = WlKh;
	DrawOdm(OdmInfo);

	return S_OK;
}

function DrawBlock(GjsbdzBlock)
{
    var             i,j;
    var             GjsbDzPos = new GJSB_DZ_POS();
    var             BlockLeftTopPos;
    var             BlockLeft, BlockTop, BlockWidth, BlockHeight;
    var             temp;
    
    BlockLeftTopPos = this.GetBlockLeftTopPos(GjsbdzBlock.MkHh, GjsbdzBlock.MkLh);
    BlockLeft = BlockLeftTopPos[0];
    BlockTop = BlockLeftTopPos[1];
    BlockWidth = this.GetBlockWidth(GjsbdzBlock.LinePerBlock);
    BlockHeight = this.GetBlockHeight(GjsbdzBlock.RowPerBlock);
    if (GjsbdzBlock.MkLh == 1)
    {
        if (this.m_objGjsbMbGlInfo.GjsbDzMbInfo.KPlf == enumPORT_LAY_UPTODOWN)
        {
            temp = GjsbdzBlock.MkHh;
        }
        else
        {
            temp = this.m_objGjsbMbGlInfo.GjsbDzMbInfo.LMks-GjsbdzBlock.MkHh+1;
        }
        //this.m_objBaseDrawBk.drawText(0, BlockLeft-3*this.m_iRad, BlockTop+this.m_iRad, temp);
        
        
        this.m_objBaseDrawBk.drawText({id:0,x:BlockLeft-3*this.m_iRad,y:BlockTop+this.m_iRad,text:temp,bsvg:true});
    }
    
    //this.m_objBaseDrawBk.drawRect(0, BlockLeft, BlockTop, BlockWidth, BlockHeight, 0, GJSB_COLOR_WHITE);
    
    this.m_objBaseDrawBk.drawRect({id:0,x:BlockLeft,y:BlockTop,w:BlockWidth,h:BlockHeight,fill:GJSB_COLOR_WHITE});
    
    for (i = 1; i <= GjsbdzBlock.RowPerBlock; i++)
    {
        for (j = 1; j <= GjsbdzBlock.LinePerBlock; j++)
        {
            GjsbDzPos.MkHh = GjsbdzBlock.MkHh;
            GjsbDzPos.MkLh = GjsbdzBlock.MkLh;
            GjsbDzPos.Row = i;
            GjsbDzPos.Line = j;
            this.DrawDz(GjsbDzPos);
        }
    }
}

function DrawEmptyBlock(iMkHh, iMkLh)
{
    var         GjsbdzBlock = new GJSBDZ_BLOCK();
    
    GjsbdzBlock.MkHh = iMkHh;
    GjsbdzBlock.MkLh = iMkLh;
    this.DrawBlock(GjsbdzBlock);
}

function GetBlockLeftTopPos(iMkHh, iMkLh)
{
    var         x, y;
    
    x = this.m_iBaseX+(iMkLh-1)*((this.m_objGjsbMbGlInfo.GetMaxLinePerBlock()+1)*this.m_iDzLineDistance+this.m_iBlockLineDistance);
    y = this.m_iBaseX+(iMkHh-1)*((this.m_objGjsbMbGlInfo.GetMaxRowPerBlock()+1)*this.m_iDzRowDistance+this.m_iBlockRowDistance);
    
    return[x, y];   
}

//得到端子板的高度
function GetBlockHeight(iDzhs)
{
    if (iDzhs == 0)
    {
        return (this.m_objGjsbMbGlInfo.GetMaxRowPerBlock()+1)*this.m_iDzRowDistance;
    }
    else
    {
        return (iDzhs+1)*this.m_iDzRowDistance;
    }
}

//得到端子板的宽度
function GetBlockWidth(iDzls)
{
    if (iDzls == 0)
    {
        return (this.m_objGjsbMbGlInfo.GetMaxLinePerBlock()+1)*this.m_iDzLineDistance;   
    }
    else
    {
        return (iDzls+1)*this.m_iDzLineDistance;
    }
}

//计算端子坐标
function CalDzCoord(GjsbDzPos)
{
    var     x, y;
    
    x = this.GetBlockLeftTopPos(GjsbDzPos.MkHh, GjsbDzPos.MkLh)[0]+GjsbDzPos.Line*this.m_iDzLineDistance;
    y = this.GetBlockLeftTopPos(GjsbDzPos.MkHh, GjsbDzPos.MkLh)[1]+GjsbDzPos.Row*this.m_iDzRowDistance; 
    
    return [x, y];   
}